package ee.metadataUtils.guice;

import java.util.Map;

import javax.inject.Inject;

import ee.metadataUtils.PropertyMetadataAdapterFactory;
import ee.metadataUtils.PropertyMetadataAdapterFactoryRegistry;

public class GuicePropertyMetadataAdapterFactoryRegistry implements PropertyMetadataAdapterFactoryRegistry {
	
	private Map<Class<?>, PropertyMetadataAdapterFactory<?>> _propertyMetadataAdapterFactories;
	
	@Inject
	public GuicePropertyMetadataAdapterFactoryRegistry(Map<Class<?>, PropertyMetadataAdapterFactory<?>> propertyMetadataAdapterFactories)
	{
		_propertyMetadataAdapterFactories = propertyMetadataAdapterFactories;
	}
	
	@Override
	public <T> void registerAdapterFactory(PropertyMetadataAdapterFactory<T> adapterFactory, Class<T> adapterType)
	{
		_propertyMetadataAdapterFactories.put(adapterType, adapterFactory);
	}
	
	@Override
	public boolean hasAdapterFactory(Class<?> adapterType)
	{
		return _propertyMetadataAdapterFactories.containsKey(adapterType);
	}
	
	@Override
	public <T> PropertyMetadataAdapterFactory<T> getAdapterFactory(Class<T> adapterType)
	{
		@SuppressWarnings("unchecked")
		PropertyMetadataAdapterFactory<T> result = (PropertyMetadataAdapterFactory<T>) _propertyMetadataAdapterFactories.get(adapterType);
		return result;
	}
}
